<?php
/**
 * 小区管理
 * comfiger
 * 2016-8-28
 **/
namespace Mama\Model;
use Think\Model;
class VillageModel extends Model{
	//定义表名称
	protected $tableName = 'village';
	
	/**
	 * 添加用户信息
	 **/
	public function registerVillageInfo($data){
		return $this->data($data)->add();
	}
	
	/**
	 * 根据条件查询总数
	 **/
	public function getVillageCount($where){
		return $this->alias('village')
					->join('left join mama_shop as shops on village.shop_id = shops.shop_id')
					->where($where)->count();
	}
	
	/**
	 * 获取用户列表
	 **/
	public function getVillageList($where){
		return $this->alias('village')
					->join('left join mama_shop as shops on village.shop_id = shops.shop_id')
					->where($where)
					->field('village.*, shops.title as shopname')
					->order('villageid desc')
					->page($page, C('PAGE_SIZE'))
					->select();
	}
	
	/**
	 * 查询小区列表
	 **/
	public function getVillageListByRegionId($regionid=1){
		return $this->where(array('region_cid' => $regionid))->order('villageid asc')->select();
	}

	/**
	 * 获取详情
	 **/
	public function getVillageInfoByVillageId($villageid){
		return $this->where(array('villageid' => $villageid))->find();
	}

	/**
	 * 编辑分店信息
	 **/
	public function editVillageInfoByShopId($villageid, $data){
		return $this->where(array('villageid' => $villageid))->setField($data);
	}
	
	/**
	 * 根据分店ID获取小区信息
	 **/
	public function getVillageListByShopId($where=array()){
		return $this->where($where)->order('villageid asc')->select();
	}
}